package thread;

public class ThreadTimeTest {

    public static void selectA() {
        System.err.println("查询A");
        // 模拟查询时间
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void selectB() {
        System.err.println("查询B");
        // 模拟查询时间
        try {
            Thread.sleep(300);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static class ThreadA implements Runnable{
        @Override
        public void run() {
            System.err.println("线程A查询中");
            selectA();
        }
    }

    public static class ThreadB implements Runnable{
        @Override
        public void run() {
            System.err.println("线程B查询中");
            selectB();
        }
    }

    public static void main(String[] args) throws InterruptedException {
        long time1 = System.currentTimeMillis();
        selectA();
        selectB();
        long time2 = System.currentTimeMillis();
        System.err.println("111===== " + (time2 - time1));

        Thread t1 = new Thread(new ThreadA());
        t1.start();
        Thread t2 = new Thread(new ThreadB());
        t2.start();
        t2.join();
        t1.join();
        long time3 = System.currentTimeMillis();
        System.err.println("222===== " + (time3 - time2));
    }
}
